package com.foreknow.filter;

import javax.servlet.*;

import java.io.IOException;
import java.util.logging.LogRecord;

public class characterEncodingFilter implements Filter {
    private  FilterConfig config;
    private String encoding = "ISO8859-1";

    @Override
    public void init(FilterConfig config) throws ServletException {
        this.config = config;
        encoding = config.getInitParameter("encoding");//utf-8
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        servletResponse.setContentType("text/html;charset=utf-8");
        filterChain.doFilter(request,servletResponse);
    }

    @Override
    public void destroy() {
        config = null;
    }



}
